﻿package com.wandian.view.mediator.account
{
	import com.wandian.controller.AccountCommand;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.InRoomPlayerDataProxy;
	import com.wandian.model.SwfDataProxy;
	import com.wandian.model.vo.PlayerVo;
	import com.wandian.model.vo.PropVo;
	import com.wandian.model.vo.RoomVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZLlistScrollPanel;
	import com.wandian.util.CLZLoadingData;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.GolbalTimer;
	import com.wandian.view.components.ui.AddBtn;
	import com.wandian.view.components.ui.MaskTipPanel;
	import com.wandian.view.components.ui.PropGiftInfo;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import org.puremvc.as3.interfaces.*;
	import org.puremvc.as3.patterns.mediator.*;
	/**  
	 * 道具礼品
	 * @author long
	 * @QQ 108232706
	 * @version 1.0   
	 */ 
    public class PropGiftMediator extends Mediator
    {
        private var _tabBar:CLZTabBar;
        private var _arrShowProp:Array;
        private var _recordPropNum:int;
        private var _arrAllProp:Array;
        private var _minType:String;
        private var _global:GameData;
        public static const NAME:String = "PropGiftMediator";

        public function PropGiftMediator(param1:Object = null, param2:String = "")
        {
            this._arrShowProp = [];
            this._global = GameData.getInstance();
            this._minType = param2;
            super(NAME, param1);
            return;
        }

        override public function onRegister() : void
        {
            this.init();
            return;
        }

        private function init() : void
        {
            var _loc_1:Array = [[this.mcPropGift.myProp_btn, GameData.tip["MYPROP"]], [this.mcPropGift.myGift_btn, GameData.tip["MYGIFT"]], [this.mcPropGift.expire_btn, GameData.tip["EXPIRE"]]];
            this._tabBar = new CLZTabBar(_loc_1);
            var _loc_2:int = 0;
            while (_loc_2 < _loc_1.length)
            {
                
                _loc_1[_loc_2][0].addEventListener(Event.CHANGE, this.changeTabBarHandler);
                _loc_2 = _loc_2 + 1;
            }
            this.sendNotification(CLZNoticeName.MY_PROP_LIST_REQ);
            CLZLoadingData.show(this.mcPropGift.conten_mc, 735, 420);
            return;
        }

        private function changeTabBarHandler(event:Event) : void
        {
            GameData.removeNumChildre(this.mcPropGift.conten_mc);
            var _loc_2:Array = [];
            switch(event.target.name)
            {
                case "myProp_btn":
                {
                    this.showMyPropList(this._arrAllProp[0], 1);
                    break;
                }
                case "myGift_btn":
                {
                    this.showMyPropList(this._arrAllProp[1], 0);
                    break;
                }
                case "expire_btn":
                {
                    this.showMyPropList(this._arrAllProp[2], 0);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        private function showMyPropList(param1:Array, param2:int = 0) : void
        {
            var _loc_6:Array = null;
            var _loc_7:int = 0;
            var _loc_8:Boolean = false;
            var _loc_9:PropVo = null;
            var _loc_10:int = 0;
            var _loc_11:PropVo = null;
            var _loc_12:MovieClip = null;
            var _loc_13:PlayerVo = null;
            var _loc_14:Boolean = false;
            GameData.removeNumChildre(this.mcPropGift.conten_mc);
            if (param1 != null)
            {
            }
            if (param1.length == 0)
            {
                return;
            }
            var _loc_3:* = new CLZLlistScrollPanel(6, 102, 151, 20, 20, 405, 728, 0);
            this.mcPropGift.conten_mc.addChild(_loc_3);
            this._arrShowProp = [];
            var _loc_4:* = param1.length;
            var _loc_5:* = facade.retrieveProxy(InRoomPlayerDataProxy.NAME) as InRoomPlayerDataProxy;
            if (param2)
            {
                _loc_6 = [];
                _loc_7 = 0;
                while (_loc_7 < _loc_4)
                {
                    
                    _loc_8 = false;
                    _loc_9 = param1[_loc_7];
                    _loc_9.number = _loc_9.num;
                    _loc_10 = 0;
                    while (_loc_10 < _loc_6.length)
                    {
                        
                        _loc_11 = _loc_6[_loc_10] as PropVo;
                        if (_loc_9.pcate == _loc_11.pcate)
                        {
                        }
                        if (_loc_9.pframe == _loc_11.pframe)
                        {
                        }
                        if (_loc_7 != _loc_10)
                        {
                            _loc_11.number = _loc_11.number + _loc_9.number;
                            _loc_8 = true;
                        }
                        _loc_10 = _loc_10 + 1;
                    }
                    if (!_loc_8)
                    {
                        _loc_6.push(_loc_9);
                    }
                    _loc_7 = _loc_7 + 1;
                }
                _loc_4 = _loc_6.length;
                _loc_7 = 0;
                while (_loc_7 < _loc_4)
                {
                    
                    _loc_12 = GameData.getMovieClip("GiftMc");
                    _loc_3.setMc(_loc_12, _loc_7, _loc_4);
                    this._arrShowProp[_loc_7] = new PropGiftInfo(_loc_12, _loc_6[_loc_7], _loc_7, false);
                    this._arrShowProp[_loc_7].addEventListener(Event.CHANGE, this.changePropHandler);
                    _loc_7 = _loc_7 + 1;
                }
            }
            else if (GameData._objRoom != null)
            {
                _loc_13 = _loc_5.getInRoomPlayer(this._global.userInfo.userVo.userid);
                _loc_14 = false;
                _loc_7 = 0;
                while (_loc_7 < _loc_4)
                {
                    
                    _loc_9 = param1[_loc_7] as PropVo;
                    if (_loc_9 != null)
                    {
                    }
                    if (_loc_9.pcate == _loc_13.giftPcate)
                    {
                    }
                    if (_loc_9.pframe == _loc_13.giftPframe)
                    {
                    }
                    if (!_loc_14)
                    {
                        _loc_14 = true;
                        _loc_9.state = 1;
                        param1.splice(_loc_7, 1);
                        param1.unshift(_loc_9);
                    }
                    else
                    {
                        _loc_9.state = 0;
                    }
                    _loc_7 = _loc_7 + 1;
                }
                _loc_7 = 0;
                while (_loc_7 < _loc_4)
                {
                    
                    _loc_12 = GameData.getMovieClip("GiftMc");
                    _loc_3.setMc(_loc_12, _loc_7, _loc_4);
                    this._arrShowProp[_loc_7] = new PropGiftInfo(_loc_12, param1[_loc_7], _loc_7, false);
                    this._arrShowProp[_loc_7].addEventListener(Event.CHANGE, this.changePropHandler);
                    _loc_7 = _loc_7 + 1;
                }
            }
            return;
        }

        private function changePropHandler(event:Event) : void
        {
            if (this._recordPropNum != event.target.num)
            {
                this._arrShowProp[this._recordPropNum].recoveryState();
            }
            this._recordPropNum = event.target.num;
            this._arrShowProp[this._recordPropNum].clickThis();
            return;
        }

        private function showMyGiftList(param1:Array) : void
        {
            var _loc_5:MovieClip = null;
            GameData.removeNumChildre(this.mcPropGift.conten_mc);
            if (param1 != null)
            {
            }
            if (param1.length == 0)
            {
                return;
            }
            var _loc_2:* = new CLZLlistScrollPanel(6, 102, 151, 20, 20, 420, 735);
            this.mcPropGift.conten_mc.addChild(_loc_2);
            this._arrShowProp = [];
            var _loc_3:* = param1.length;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3)
            {
                
                _loc_5 = GameData.getMovieClip("GiftMc");
                _loc_2.setMc(_loc_5, _loc_4, _loc_3);
                this._arrShowProp[_loc_4] = new PropGiftInfo(_loc_5, param1[_loc_4], _loc_4, false);
                this._arrShowProp[_loc_4].addEventListener(Event.CHANGE, this.changePropHandler);
                _loc_4 = _loc_4 + 1;
            }
            return;
        }

        override public function listNotificationInterests() : Array
        {
            return [CLZNoticeName.MY_PROP_LIST_RES, CLZNoticeName.RENEW_GIFT_RES];
        }

        override public function handleNotification(param1:INotification) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:PropVo = null;
            var _loc_5:PropVo = null;
            switch(param1.getName())
            {
                case CLZNoticeName.MY_PROP_LIST_RES:
                {
                    CLZLoadingData.hide(this.mcPropGift.conten_mc);
                    this._arrAllProp = param1.getBody() as Array;
                    if (this._minType == "GIFT")
                    {
                        this._tabBar.setClickIndex(this.mcPropGift.myGift_btn);
                    }
                    else
                    {
                        this._tabBar.setClickIndex(this.mcPropGift.myProp_btn);
                    }
                    this._minType = "";
                    break;
                }
                case CLZNoticeName.RENEW_GIFT_RES:
                {
                    _loc_2 = param1.getBody() as int;
                    _loc_3 = 0;
                    while (_loc_3 < this._arrAllProp[2].lenght)
                    {
                        
                        _loc_4 = this._arrAllProp[2][_loc_3] as PropVo;
                        if (_loc_2 == _loc_4.id)
                        {
                            this._arrAllProp[2].splice(_loc_3, 1);
                            _loc_5 = GameData.getPropById(_loc_4.pcate, _loc_4.pframe);
                            _loc_4.validity = _loc_5.validity;
                            this._arrAllProp[1].push(_loc_4);
                            break;
                        }
                        _loc_3 = _loc_3 + 1;
                    }
                    this._tabBar.setClickIndex(this.mcPropGift.expire_btn);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        private function get mcPropGift() : MovieClip
        {
            return viewComponent as MovieClip;
        }

    }
}
